package demo1;

class OuterClass{

    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;
    //静态内部类
    static class InnerClass{
        public int data4 = 4;
        private int data5 = 5;
        public static int data6 = 6;

        public void func(){
            System.out.println("static -> InnerClass::func()");
            OuterClass outerClass = new OuterClass();
            //所有静态的（类/方法）都不依赖对象。不能直接访问静态类外的非静态成员，要通过引用才能访问
            System.out.println(outerClass.data1);
            System.out.println(outerClass.data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }
    public void test(){
        InnerClass innerClass = new InnerClass();
        System.out.println(data1);
        System.out.println(data2);
        System.out.println(data3);
        //此时为什么不能直接访问下面这三个对象？
        System.out.println(innerClass.data4);
        System.out.println(innerClass.data5);//外部类可以访问静态内部类当中所有成员，哪怕是privated
        System.out.println(innerClass.data6);
    }
}
public class Test {
    public static void main(String[] args) {
//        InnerClass innerClass = new InnerClass();
//    可以看出，静态内部类不能直接实例化
        OuterClass.InnerClass innerClass = new OuterClass.InnerClass();
        innerClass.func();
    }
}
